<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>JSONP</title>
</head>

<body>

    <script>
        JSONP('https://c.y.qq.com/v8/fcg-bin/getmv_by_tag?g_tk=5381', {
                a: 5,
                b: 10
            }, 'jsonpCallback')
            .then((data) => {
                console.log(data);
            })

        function JSONP(url, data, callBackName) {
            callBackName = callBackName || 'callback';
            var script = document.createElement('script');
            var callback = 'JSONP_' + parseInt(89999 * Math.random() + 10000) + '_' + (+new Date());
            script.src = url.indexOf('?') > 0 ? url + '&' + callBackName + '=' + callback + queryString(data) : url +
                '?' + callBackName + '=' + callback + queryString(data);
            var head = document.getElementsByTagName('head')[0];
            head.appendChild(script);
            var timer = null;
            return new Promise((resolve, reject) => {
                window[callback] = function (data) {
                    clearTimeout(timer);
                    head.removeChild(script);
                    resolve(data);
                };
                timer = setTimeout(() => {
                    reject(new Error('请求超时'));
                }, 30000);
            })

            function queryString(data) {
                var str = '';
                let vaule = data[key] != undefined ? data[key] : '';
                for (let key in data) {
                    str += '&' + key + '=' + encodeURIComponent(value);
                }
                return str;
            }
        }
    </script>
</body>

</html>